package com.zhanggm.springcloud.car.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhanggm.springcloud.car.service.ICarService;
import com.zhanggm.springcloud.common.entity.Car;
import org.hibernate.validator.constraints.EAN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 车辆表 前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2020-12-12
 */
@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    private ICarService iCarService;

    @GetMapping("getById")
    public Car getById(@RequestParam("id") Integer id){
        return iCarService.getById(id);
    }

    @GetMapping("listAll")
    public List<Car> listAll(){
        List<Car> list = iCarService.list();
        return list;
    }

    @GetMapping("listByName")
    public List<Car> listByName(@RequestParam("name") String name){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("name",name);
        List<Car> list = iCarService.list(queryWrapper);
        return list;
    }

    @GetMapping("getListByIds")
    public List<Car> getListByIds(@RequestParam("ids") List<Integer> ids){
        return iCarService.listByIds(ids);
    }
}
